package mercurius.fitness.client.rb.measurement;

import java.util.ArrayList;
import java.util.Date;
import mercurius.fitness.client.locale.Locale;
import net.pleso.framework.client.bl.rb.columns.impl.RBColumn;
import net.pleso.framework.client.dal.IDataColumn;
import net.pleso.framework.client.dal.IDataRow;
import net.pleso.framework.client.dal.db.IDBValue;
import net.pleso.framework.client.dal.db.types.DBDate;
import net.pleso.framework.client.dal.db.types.DBFloat;
import net.pleso.framework.client.dal.db.types.DBInteger;
import net.pleso.framework.client.dal.db.types.DBString;
import net.pleso.framework.client.dal.impl.DataColumn;

public class Measurements extends MeasurementsInfo implements IDataRow {
	
	public Measurements() {
		
	}
	
	public Measurements(Integer id, Float weight,Float fat,Date date,String notes,Integer pulse,String milestone) {
		super(id, weight,fat,date,notes,pulse,milestone);
	}
	
	public class id_column extends Columns {
		public id_column() {
			super("id", "Measurements ID", false);
		}

		public IDBValue getCell(Measurements row) {
			return new DBInteger(row.getID());
		}

		public void setCell(Measurements row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setID(((DBInteger) value).getInteger());
		}
	}
	
	
	public class date_column extends Columns {

		public date_column() {
			super("date", Locale.constants().measurement_date_column(), false);
		}

		public IDBValue getCell(Measurements row) {
			return new DBDate(row.getDate());
		}

		public void setCell(Measurements row, IDBValue value) {
			if (value instanceof DBDate)
				row.setDate(((DBDate) value).getDate());
		}
	}	
	
	
	public class weight_column extends Columns {
		public weight_column() {
			super("weight", Locale.constants().measurement_weight_column(), true);
		}

		public IDBValue getCell(Measurements row) {
			return new DBFloat(row.getWeight());
		}

		public void setCell(Measurements row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setWeight(((DBFloat) value).getFloat());
		}
	}
	
	public class fat_column extends Columns {
		public fat_column() {
			super("fat", Locale.constants().measurement_fat_column(), true);
		}

		public IDBValue getCell(Measurements row) {
			return new DBFloat(row.getFat());
		}

		public void setCell(Measurements row, IDBValue value) {
			if (value instanceof DBFloat)
				row.setFat(((DBFloat) value).getFloat());
		}
	}
	
	public class restingpulse_column extends Columns {
		public restingpulse_column() {
			super("restingpulse", Locale.constants().measurement_restingpulse_column(), true);
		}

		public IDBValue getCell(Measurements row) {
			return new DBInteger(row.getRestingPulse());
		}

		public void setCell(Measurements row, IDBValue value) {
			if (value instanceof DBInteger)
				row.setRestingPulse(((DBInteger) value).getInteger());
		}
	}
	
	public class milestone_column extends Columns {
		public milestone_column() {
			super("milestone", Locale.constants().measurement_milestone_column(), true);
		}

		public IDBValue getCell(Measurements row) {
			return new DBString(row.getMilestone());
		}

		public void setCell(Measurements row, IDBValue value) {
			if (value instanceof DBString)
				row.setMilestone(((DBString) value).getString());
		}
	}
	
	public class notes_column extends Columns {
		public notes_column() {
			super("notes", Locale.constants().measurement_notes_column(), true);
		}

		public IDBValue getCell(Measurements row) {
			return new DBString(row.getNotes());
		}

		public void setCell(Measurements row, IDBValue value) {
			if (value instanceof DBString)
				row.setNotes(((DBString) value).getString());
		}
	}
	
	
	
	
	private static ArrayList columns = new ArrayList();
	private static final Measurements instance = new Measurements();
	
	public static RBColumn[] getColumns() {
		RBColumn[] rbColumns = new RBColumn[] {
				new RBColumn(Measurements.Columns.id, 30),
				new RBColumn(Measurements.Columns.date, 30),
				new RBColumn(Measurements.Columns.weight, 30),
				new RBColumn(Measurements.Columns.fat, 30)
		};
		return rbColumns;
	}
	
	public abstract static class Columns extends DataColumn {
		
		public Columns(String name, String caption, boolean allowNull) {
			super(name, caption, allowNull);
			columns.add(this);
			this.order = columns.size(); 
		}
		
		
		public abstract void setCell(Measurements row, IDBValue value);
		public abstract IDBValue getCell(Measurements row);
		
		public static final id_column id = instance.new id_column();
		public static final date_column date = instance.new date_column();
		public static final weight_column weight = instance.new weight_column();
		public static final fat_column fat = instance.new fat_column();
		public static final notes_column notes = instance.new notes_column();
		public static final milestone_column milestone = instance.new milestone_column();
		public static final restingpulse_column restingpulse = instance.new restingpulse_column();
	}

	public IDBValue getCell(IDataColumn column) {
		Columns col = (Columns) column;
		return col.getCell(this);
	}

	public IDataColumn getColumn(int index) {
		return (IDataColumn) columns.get(index);
	}

	public int getColumnCount() {
		return columns.size();
	}

	public void setCell(IDataColumn column, IDBValue value) {
		Columns col = (Columns) column;
		col.setCell(this, value);
	}

}
